/**
 * // Definition for a Node.
 * function Node(val, next, random) {
 *    this.val = val;
 *    this.next = next;
 *    this.random = random;
 * };
 */

/**
 * @param {Node} head
 * @return {Node}
 */
var copyRandomList = function (head) {
    if (!head) {
        return null
    }
    let map = new Map();
    let headd = head;
    while (headd) {
        map.set(headd, new Node(headd.val))
        headd = headd.next;
    }
    headd = head;
    while (headd) {
        map.get(headd).next = map.get(headd.next) || null;
        map.get(headd).random = map.get(headd.random) || null;
        headd = headd.next;
    }

    return map.get(head);
};